<template>
    <div class="layout" style="overflow: auto;" v-if="$store.state.login">
        <Layout>
            <Header>
                <Menu mode="horizontal" theme="dark" active-name="1">
                    <div class="layout-logo"></div>
                    <div class="layout-nav" style="font-size: 25px; color: #FFFFFF;text-align: right;">
                        {{timeStr}}
                    </div>
                </Menu>
            </Header>
            <Layout :style="{padding: '0 50px'}">
                <Breadcrumb :style="{margin: '16px 0'}">
                    <BreadcrumbItem>Home</BreadcrumbItem>
                    <BreadcrumbItem>Components</BreadcrumbItem>
                    <BreadcrumbItem>Layout</BreadcrumbItem>
                </Breadcrumb>
                <Content :style="{padding: '24px 24px 0 0', background: '#fff'}">
                    <Layout>
                        <Sider hide-trigger :style="{background: '#fff'}">
                            <Menu active-name="1-2" theme="light" width="auto" :open-names="['1']">
                                <Submenu name="1">
                                    <template slot="title">
                                        <Icon type="ios-navigate"></Icon>
                                        	功能管理
                                    </template>
                                    <router-link to='/user'>
                                    	<MenuItem name="1-1">
	                                    	用户管理
	                                    </MenuItem>
                                    </router-link>
                                    
                                    <router-link to='/cate'>
                                    	<MenuItem name="1-2">
	                                    	分类管理
	                                    </MenuItem>
                                    </router-link>
                                    <router-link to='/information'>
                                    	<MenuItem name="1-3">
	                                    	信息管理
	                                    </MenuItem>
                                    </router-link>
                                    <router-link to='/product'>
                                    	<MenuItem name="1-4">
	                                    	产品管理
	                                    </MenuItem>
                                    </router-link>
                                    <router-link to='/comment'>
                                    	<MenuItem name="1-5">
	                                    	评论管理
	                                    </MenuItem>
                                    </router-link>
                                    <router-link to='/order'>
                                    	<MenuItem name="1-6">
	                                    	订单管理
	                                    </MenuItem>
                                    </router-link>
                                     <router-link to='/picture'>
                                    	<MenuItem name="1-7">
	                                    	相册管理
	                                    </MenuItem>
                                    </router-link>
                                    
                                </Submenu>
                                <Submenu name="2">
                                    <template slot="title">
                                        <Icon type="ios-keypad"></Icon>
                                        	帮助中心
                                    </template>
                                    <router-link to='/helper'>
                                    	<MenuItem name="2-1">
	                                    	帮助中心
	                                    </MenuItem>
                                    </router-link>
                                </Submenu>
                                <Submenu name="3">
                                    <template slot="title">
                                        <Icon type="ios-analytics"></Icon>
                                        Item 3
                                    </template>
                                    <MenuItem name="3-1">Option 1</MenuItem>
                                    <MenuItem name="3-2">Option 2</MenuItem>
                                </Submenu>
                            </Menu>
                        </Sider>
                        <Content :style="{paddingLeft: '24px', minHeight: '450px', background: '#fff'}">
							<router-view></router-view>
                        </Content>
                    </Layout>
                </Content>
            </Layout>
            <Footer class="layout-footer-center" style="padding-top: 10px!important;">2011-2016 &copy; TalkingData</Footer>
        </Layout>
</div>
<div v-else style="margin: 100px auto; width: 300px;">
	<h1 style="font-size: 35px;">Welcome</h1>
	<Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
        <FormItem prop="user">
            <Input type="text" v-model="formInline.user" placeholder="Username" style="width: 250px; margin-bottom: 15px;">
                <Icon type="ios-person-outline" slot="prepend"></Icon>
            </Input>
        </FormItem>
        <FormItem prop="password">
            <Input type="password" v-model="formInline.password" placeholder="Password" style="width: 250px;margin-bottom: 15px;">
                <Icon type="ios-lock-outline" slot="prepend"></Icon>
            </Input>
        </FormItem>
        <FormItem>
            <Button type="primary" @click="handleSubmit('formInline')">Signin</Button>
        </FormItem>
    </Form>
</div>


</template>
<script>
    export default {
    	 data () {
            return {
            	timeStr:'',
                formInline: {
                    user: '',
                    password: ''
                },
                ruleInline: {
                    user: [
                        { required: true, message: 'Please fill in the user name', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: 'Please fill in the password.', trigger: 'blur' },
                        { type: 'string', min: 6, message: 'The password length cannot be less than 6 bits', trigger: 'blur' }
                    ]
                }
            }
        },
         methods: {
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                	console.log(valid);
                    if (valid) {
                    	this.axios({
		        			url:this.GLO.myUrl+'users/login',
		        			method:'post',
		        			data:{
		        				name:this.formInline.user,
		        				password:this.formInline.password
		        			}
		        		}).then(res=>{
		        			if(res.data){
		        				this.$store.dispatch('setlogin',true);
		        				console.log(res.data.token);
		        				this.$store.dispatch('settoken',res.data.token);
		        				console.log(this.$store.state.token);
		        				 this.$Message.success('登录成功!');
		        			}else{
		        				this.$Message.error('用户名或密码错误');
		        			}
		        		})
                       
                    } else {
                        this.$Message.error('用户名或密码错误');
                    }
                })
            }
        },
        mounted(){
        	setInterval(()=>{
        		var date=new Date();
        		this.timeStr=date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
        	},1000)
        	
        	
//      	$('#login').on('click',()=>{
//      		this.axios({
//      			url:'http://localhost:3000/users/login',
//      			method:'post',
//      			data:{
//      				name:$('#name').val(),
//      				password:$('#pas').val()
//      			}
//      		}).then(res=>{
//      			if(res.data){
//      				this.$store.dispatch('setlogin',true);
//      				console.log(res.data.token);
//      				this.$store.dispatch('settoken',res.data.token);
//      				console.log(this.$store.state.token);
//      			}
//      		})
//      	})
        	
        }
    }
</script>

<style scoped>
.layout{
    border: 1px solid #d7dde4;
    background: #f5f7f9;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    height: 100%;
}
.layout-logo{
    width: 100px;
    height: 30px;
    background: #5b6270;
    border-radius: 3px;
    float: left;
    position: relative;
    top: 15px;
    left: 20px;
}
.layout-nav{
    width: 420px;
    margin: 0 auto;
    margin-right: 20px;
}
.layout-footer-center{
    text-align: center;
}
</style>
